package ar.edu.itba.it.atlc.model;

import ar.edu.itba.it.atlc.model.Transition.Symbol;

public class Square {

	private Square leftSquare;
	private Square rightSquare;
	private Symbol value;

	public Square(Symbol value) {
		this.value = value;
	}

	public Symbol getValue() {
		return value;
	}

	public Square addRightSquare(Symbol value) {
		rightSquare = new Square(value);
		rightSquare.leftSquare = this;
		return rightSquare;
	}

	public Square addLeftSquare(Symbol value) {
		leftSquare = new Square(value);
		leftSquare.rightSquare = this;
		return leftSquare;
	}

	public Square moveLeft() {
		if (!hasLeft()) {
			return addLeftSquare(Symbol.Symbol_0);
		}
		return leftSquare;
	}

	public Square moveRight() {
		if (!hasRight()) {
			return addRightSquare(Symbol.Symbol_0);
		}
		return rightSquare;
	}

	public boolean hasRight() {
		if (rightSquare == null) {
			return false;
		}
		return true;
	}

	public boolean hasLeft() {
		if (leftSquare == null) {
			return false;
		}
		return true;
	}

	public void write(Symbol value2) {
		this.value = value2;

	}

	@Override
	public String toString() {
		return value.toString();
	}
}
